#include "confighelper.h"
#include <QSettings>
#include <QMutex>
#include <QFile>

Confighelper* Confighelper::instance = nullptr;

Confighelper* Confighelper::getInstance()
{
    static QMutex mutex;
    if (!instance) {
        QMutexLocker locker(&mutex);
        if (!instance)
        {
            instance = new Confighelper();
        }
    }
    return instance;
}

void Confighelper::writeIniFile(QString key, QString val)
{
    QSettings settings("config.ini", QSettings::IniFormat);
    settings.setValue(key, val);
}

QString Confighelper::readIniFile(QString key)
{
    QSettings settings("config.ini", QSettings::IniFormat);
    return settings.value(key).toString();
}

void Confighelper::init()
{
    QFile file("config.xml");
    if(!file.exists())
    {
        writeIniFile("FullScreen", "Alt+F");
        writeIniFile("Selection", "Alt+S");
    }
}
